{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2b7bddde",
   "metadata": {},
   "source": [
    "# IIR滤波器结构：级联型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "137c30fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAbgAAAEoCAYAAAAqrOTwAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAheElEQVR4nO3df5QddX3/8ecrIYkrFAMmtWQFApamVQKNZw8mwhcjBSOINY21+K0etbYH1NbTFokmB6uUFomm9A9La5MWUKhSkcZUq3zDLyM/BMLGCAEhx8qP0BAkAUIaXEjcvL9/zKxclt3NzmTunbkzr8c5e87uvXdmPrOf2Xnt5zOfz4wiAjMzs7qZUHYBzMzM2sEBZ2ZmteSAMzOzWnLAmZlZLTngzMyslhxwZg0nSXneM6s6B5xZgSSdKunwcXxuoqQJLT9L0mRJf9jy2iclHdjy8yslHTBsPZNbvj9cUn/G8p4FfHyMj3w8/YxZ13HAmaUkfVnSR8Z6TdIFknZJelLSFkmfaHlvAvB3wEGS5kv6kaSHJN0m6S5Jd7es+l3AY5IelHQP8DOSoHmXpLdJOhZ4NzDQssyFwP2SNqfrfB74qqSTJX0VeCH9QtKHJH15H/t7BHAO8M9jfGwF8FFJR461LrMqOmDfHzGzYS6NiCWSZgLrJN0YEfcAfwR8G3gOmA0sAC6LiDMlnQH8/tAKImKVpOOAB4FHgI8A1wJ7gT7gWOAm4J3Af6bLnCdpPfDrwMXAf0fEeyTNBfaky2a5c8OFwHkRsXu0D0TEC5IWA38NfCjDus1K5xacWU4R8QhwJzBLUh9wPrARuBQYBCYBQ+HxVuD6EVZzEXBF+n0P8HOgFziYJPx+FUDSTEkfA04Dfhv4MElL8aPAtKxllzQFODIifjiO/bwbODpdxqxrOOD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u/lWXWPwtS4zs+6liOj8RqVtwKMFrW4asL2gdXUb73tzNXn/ve/NNdL+HxkRI849KyXgiiSpPyL6yi5HGbzvzdx3aPb+e9+bue+Qff9rMWfNzMxsOAecmZnVUh0CbmXZBSiR9725mrz/3vfmyrT/XX8NzszMbCR1aMGZmZm9jAOuC0k6QNLmlic9zC67TNZerQ8adv03h6RXSbpO0vWSvilpcpPqXtKhkk6TNC3P8l0bcA1/ivhxwNURMT/92lh2gTph+NPkm3IMjPCg4cbU/ygn+EbUe+p9wN9HxNuAJ4AlNKfuDwH+CzgB+J6k6VnrvisDzk8RZy5wpqR1aYXX/o40w0/yDTsGhj9ouEn1P/wE/16aU+9ExD9FxA3pj9OBX9Ccuj8OODciLgLWAKeQse67MuAY51PEa+xu4NSIOAGYBJxRcnk6YfhJfj4NOQYiYuewm5g3pv5HOMG/n4bUeytJ84BDgBtoTt1/PyLulHQySStuARnrvlsDblxPEa+xeyNia/p9P1Dr/2JhxJN8k4+BxtV/ywn+MRpW75IOBf4B+DANq3tJIvnH9hkgyFj33RpwtXyKeAZXSTpe0kRgIXBPyeUpQ5OPgUbV/7ATfKPqXdJk4BvA0oh4lIbVfST+FLgXeDMZ675bD46hp4hD8hTxR8orSikuBK4CfgTcERE3llucUjT5GGhM/Y9wgm9avf8x8EbgfElrgftpTt1/StIH0h+nAsvIWPddOdFb0sHArcBNpE8Rr8uDVm1sktZGxHwfA80g6aPA53ixpXIFcC6u99pLB5ZdA0wB7gOWAreQoe67MuDglzt/GnBLRDxRdnms83wMNJPrvbmy1n3XBpyZmdlYuvUanJmZ2ZgccGZmVksOODMzqyUHnJmZ1ZIDzszMaun/A5nKHcmzmuN6AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#libraries\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy import signal\n",
    "\n",
    "#parameters of defference equation\n",
    "A = 3;b = np.array([[1,1,0],[1,-3.14,1]]) #numerator\n",
    "a = np.array([[1,-0.6,0],[1,0.7,0.72]]) #denominator\n",
    "\n",
    "#input signal\n",
    "M = a.shape[0];N = 30\n",
    "delta = signal.unit_impulse(N) #unit sample signal\n",
    "y = np.ones(N) #unit step signal\n",
    "\n",
    "#IIR casfilter\n",
    "z1 = np.zeros((M+1,N));z2 = np.zeros((M+1,N));\n",
    "z1[0,:] = delta;z2[0,:] = y; \n",
    "for i in range(M): #循环滤波，计算最终结果\n",
    "    zi = signal.lfilter_zi(b[i,:],a[i,:])*0 #zero initial condition\n",
    "    z1[i+1,:],_ = signal.lfilter(b[i,:],a[i,:],z1[i,:],zi=zi);\n",
    "    z2[i+1,:],_ = signal.lfilter(b[i,:],a[i,:],z2[i,:],zi=zi);\n",
    "\n",
    "#plot\n",
    "fig,axs = plt.subplots(2,1,constrained_layout=True)\n",
    "axs[0].stem(A*z1[M,:],basefmt=\"\");axs[1].stem(A*z2[M,:],basefmt=\"\")\n",
    "plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False #用来显示负号\n",
    "axs[0].set_title('IIR级联型h(n)');axs[1].set_title('IIR级联型y(n)')\n",
    "plt.show();fig.savefig('./iir_cas_sequence.png',dpi=500)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37d2f44a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
